package com.yin.web;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.yin.entity.MiddleSystem;
import com.yin.service.MiddleSystemService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * <p>
 * 中台系统表 前端控制器
 * </p>
 *
 * @author yinxunlian
 * @since 2021-07-28
 */
@RestController
@RequestMapping("/middleSystem")
public class MiddleSystemController {

    @Resource
    private MiddleSystemService middleSystemService;

    /**
     * 中台系统分页
     *
     * @param middleSystem
     * @return
     */
    @RequestMapping("list")
    public Object list(MiddleSystem middleSystem, Integer pageNumber, Integer pageSize) {
        if (pageNumber == null) {
            pageNumber = 1;
        }
        if (pageSize == null) {
            pageSize = 10;
        }
        Wrapper<MiddleSystem> wrapper = new EntityWrapper<>(middleSystem);
        Page<MiddleSystem> page = middleSystemService
                    .selectPage(new Page<>(pageNumber, pageSize), wrapper);
        return page;
    }

    /**
     * 中台系统详情
     *
     * @param middleSystem
     * @return
     */
    @RequestMapping("detail")
    public Object detail(MiddleSystem middleSystem) {
        MiddleSystem middleSys = middleSystemService.selectById(middleSystem.getId());
        return middleSys;
    }

    /**
     * 新增、修改中台系统
     *
     * @param middleSystem
     * @return
     */
    @RequestMapping("save")
    public Object save(MiddleSystem middleSystem) {
        middleSystemService.insert(middleSystem);
        return true;
    }

    /**
     * 删除中台系统
     *
     * @param middleSystem
     * @return
     */
    @RequestMapping("delete")
    public Object delete(MiddleSystem middleSystem) {
        middleSystemService.deleteById(middleSystem.getId());
        return true;
    }
}

